# -*- coding: utf-8 -*-
"""
Module Description:
Date: 2017/1/9
Author:FQ
"""
from pyshare.utils.time_utils import getCT, has_pass_time, get_another_time
from pyshare.dal.gameconfig.game_env import get_config_env_set
from pyshare.const.enums.activity import ActivityStatus, ActivityExtraStatusList
from common.service_config import get_ctx_time


class BaseActivityMixin(object):
    __slots__ = ()
    start_time = NotImplemented
    end_time = NotImplemented
    status = NotImplemented

    @property
    def is_extra(self):
        return self.status in ActivityExtraStatusList

    @property
    def is_time_open(self):
        # 活动时间是否有效
        return self.start_time <= getCT() < self.end_time

    @property
    def is_open(self):
        # 检测status,活动是否开启
        return self.status == ActivityStatus.Open and (self.start_time <= getCT() < self.end_time)

    @property
    def is_time_not_start(self):
        # 活动时间是否未开始
        return getCT() < self.start_time

    @property
    def is_expire(self):
        # 活动是否过期
        return self.status in ActivityExtraStatusList or self.end_time <= getCT()

    @property
    def is_expire_clear(self):
        # 是否到了活动记录删除状态
        return has_pass_time(self.end_time, days=get_config_env_set('ActivityExpireClearTime'))

    @property
    def send_time(self):
        # 定时任务发奖时间
        return get_another_time(self.end_time, seconds=30)

    @property
    def is_send(self):
        # 是否可发送奖励
        return self.status == ActivityStatus.Open and self.end_time <= getCT()

    def set_temp_value(self, value_name, value):
        """设置临时属性"""
        setattr(self, value_name, value)

    def get_temp_value(self, value_name, default=None):
        """获取临时属性"""
        return getattr(self, value_name, default)


class RankActivityMixin(BaseActivityMixin):
    __slots__ = ()
    award_end_time = NotImplemented

    @property
    def is_show(self):
        return self.status == ActivityStatus.Open and (self.start_time <= getCT() < self.award_end_time)

    @property
    def is_awarding(self):
        # 领奖时间延迟两秒
        end_time = get_another_time(self.end_time, seconds=2)
        return self.status == ActivityStatus.Open and (end_time <= get_ctx_time() < self.award_end_time)

    @property
    def is_expire(self):
        return self.status in ActivityExtraStatusList or self.award_end_time <= getCT()

    @property
    def is_expire_clear(self):
        return has_pass_time(self.award_end_time, days=get_config_env_set('ActivityExpireClearTime'))

    @property
    def send_time(self):
        # 定时任务发奖时间
        return get_another_time(self.award_end_time, seconds=30)

    @property
    def is_send(self):
        # 是否可发送奖励
        return self.status == ActivityStatus.Open and self.award_end_time <= getCT()

    def is_champion_show(self):
        # 是否可显示冠军信息
        show_end = get_another_time(self.end_time, minutes=get_config_env_set('RankActivityTheFirstShowTime'))
        return self.status == ActivityStatus.Open and self.end_time <= getCT() <= show_end


class RuinsActivityMixin(BaseActivityMixin):
    __slots__ = ()
    activity_status = NotImplemented
    award_end_time = NotImplemented
    desc_str = NotImplemented
    activity_name = NotImplemented
    activity_type = NotImplemented
    activity_id = NotImplemented

    @property
    def status(self):
        return self.activity_status

    @property
    def is_validity(self):
        return self.status == ActivityStatus.Open and (self.start_time <= getCT() < self.award_end_time)

    @property
    def send_time(self):
        # 定时任务发奖时间
        return get_another_time(self.award_end_time, seconds=30)

    @property
    def is_expire_clear(self):
        return has_pass_time(self.award_end_time, days=get_config_env_set('ActivityExpireClearTime'))

    @property
    def is_expire(self):
        return self.status in ActivityExtraStatusList or self.award_end_time <= getCT()

    def base_asdict(self):
        return {
            'DescStr': self.desc_str,
            'ActivityName': self.activity_name,
            'ActivityType': self.activity_type,
            'ActivityId': self.activity_id,
            'ActivityStatus': self.activity_status,
            'StartTime': self.start_time,
            'AwardEndTime': self.award_end_time,
            'EndTime': self.end_time,
        }


class QueenJewelryActivityMixin(BaseActivityMixin):
    __slots__ = ()
    award_end_time = NotImplemented

    @property
    def is_show(self):
        return self.status == ActivityStatus.Open and (self.start_time <= getCT() < self.award_end_time)

    @property
    def is_awarding(self):
        return self.status == ActivityStatus.Open and (self.end_time <= getCT() < self.award_end_time)

    @property
    def is_expire(self):
        return self.status in ActivityExtraStatusList or self.award_end_time <= getCT()

    @property
    def is_expire_clear(self):
        return has_pass_time(self.award_end_time, days=get_config_env_set('ActivityExpireClearTime'))

    @property
    def send_time(self):
        # 定时任务发奖时间
        return get_another_time(self.award_end_time, seconds=30)

    @property
    def is_send(self):
        # 是否可发送奖励
        return self.status == ActivityStatus.Open and self.award_end_time <= getCT()


class CrossClearanceActivityMixin(BaseActivityMixin):
    __slots__ = ()
    award_end_time = NotImplemented
    activity_status = NotImplemented

    @property
    def is_awarding(self):
        return self.activity_status == ActivityStatus.Open and (self.end_time <= getCT() < self.award_end_time)

    @property
    def is_expire(self):
        return self.activity_status in ActivityExtraStatusList or self.award_end_time <= getCT()

    @property
    def is_expire_clear(self):
        return has_pass_time(self.award_end_time, days=get_config_env_set('ActivityExpireClearTime'))

    @property
    def send_time(self):
        # 定时任务发奖时间
        return get_another_time(self.award_end_time, seconds=30)

    @property
    def is_send(self):
        # 是否可发送奖励
        return self.status == ActivityStatus.Open and self.award_end_time <= getCT()


class CrossFishActivityMixin(BaseActivityMixin):
    __slots__ = ()
    award_end_time = NotImplemented
    activity_status = NotImplemented

    @property
    def is_awarding(self):
        return self.activity_status == ActivityStatus.Open and (self.end_time <= getCT() < self.award_end_time)

    @property
    def is_open(self):
        # 检测status,活动是否开启
        return self.activity_status == ActivityStatus.Open and (self.start_time <= getCT() < self.end_time)

    @property
    def is_expire(self):
        return self.activity_status in ActivityExtraStatusList or self.award_end_time <= getCT()

    @property
    def is_expire_clear(self):
        return has_pass_time(self.award_end_time, days=get_config_env_set('ActivityExpireClearTime'))

    @property
    def send_time(self):
        # 定时任务发奖时间
        return get_another_time(self.award_end_time, seconds=30)

    @property
    def is_send(self):
        # 是否可发送奖励
        return self.status == ActivityStatus.Open and self.award_end_time <= getCT()
